package com.fingard.remoting.client;

import com.fingard.io.FileHelper;
import com.fingard.text.StringHelper;
import com.fingard.xml.XmlTextReader;

public class TenantClientSet {
/**    <!-- 远程客户端配置，用于部署在企业用户端，作为代理服务 -->
    <enable readme="是否启用">true</enable>
    <tenantCode readme="租户ID">zjsdyx</tenantCode>
    <!-- 运行模式，clientAsServer，作为客户端向远程服务发起建立长链接，再作为服务端接收远程的请求 -->
    <runMode readme="运行模式">clientAsServer</runMode>
    <ownPublicKey readme="本方公钥"></ownPublicKey>
    <ownPrivateKey readme="本方私钥"></ownPrivateKey>
    <remotePublicKey readme="远程服务公钥，即对方公钥"></remotePublicKey>
    <remoteServerList readme="远程服务">127.0.0.1:6060,127.0.0.1:6061</remoteServerList>
    
    */
	
	public boolean enable;
	public String tenantCode;
	public String runMode;
	public String ownPublicKey;
	public String ownPrivateKey;
	public String remotePublicKey;
	public String remoteServerList;
	
	public String charset;
	
	/**心跳间隔时间，单位：秒*/
	public int hbIntervalSecs;
	
	public void loadFromXmlFile(String pXmlFilePath) throws Exception{
		if(!FileHelper.existFile(pXmlFilePath)){
			return;
		}
		String configText = FileHelper.readFileText(pXmlFilePath, "utf-8");
		XmlTextReader reader = new XmlTextReader(configText);
		if("true".equals(reader.getSimpleTextNotNull("enable").toLowerCase())){
			enable = true;
		}else{
			enable = false;
		}
		tenantCode = reader.getSimpleTextNotNull("tenantCode");
		runMode = reader.getSimpleTextNotNull("runMode");
		charset = reader.getSimpleTextNotNull("charset");
		ownPublicKey = reader.getSimpleTextNotNull("ownPublicKey");
		ownPrivateKey = reader.getSimpleTextNotNull("ownPrivateKey");
		remotePublicKey = reader.getSimpleTextNotNull("remotePublicKey");
		remoteServerList = reader.getSimpleTextNotNull("remoteServerList");
		String secs = reader.getSimpleTextNotNull("hbIntervalSecs");
		if(StringHelper.hasAnyChar(secs)){
			hbIntervalSecs = Integer.parseInt(secs);
		}else{
			hbIntervalSecs = 5;//默认5秒
		}
	}
	
}
